<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>APITable Browser Test</title>
  <script src="../apitable.browser.js"></script>
</head>

<body>
  <pre><code id="V_CODE"></code></pre>
  <input id="input" name="file" type="file" accept="*">

  <script>
    function print(r) {
      document.getElementById('V_CODE').innerText = JSON.stringify(r, null, 2);
    }
    APITable.auth({
      token: "your api token",
    });
    const datasheet = APITable.datasheet('datasheet id');
    datasheet.all().then(r => {
      print(r);
    });

    const input = document.getElementById('input');
    input.onchange = function () {
      const file = this.files[0];
      console.log('file', file);
      // NodeJs can pass in a Buffer or stream to get the file using the input element in the browser.
      print('uplaoding');
      datasheet.upload(file).then(response => {
        /**
         * response data
         *   success: boolean
         *   code: number
         *   message: string
         *   data: IAttachment
         */
        print(response);
      });
    };
  </script>
</body>

</html>